/**
 * Created by Administrator on 2016-12-27.
 */


const http = require('http');
const cheerio = require('cheerio');

var req = http.request({


    hostname: 'el.inspur.com',
    path: '/tms/MyOfflineTrainPersonalSign.aspx?childMenuCode=tms_user_offline_sign&parentMenuCode=lesson_user_center',

    headers: {
         Cookie:'__Newv-Passport__=Do/4Qy0fXVrBmgYWeja3s07bX6hSdp6usFxS1oZIaGRseWT6HvcZcYHDWcpLxWKwcQ5Zecd/NXnmu3UMC1DO/fqBc+mEm6BTJxzSGUzk8z/xAumaisw8yCNYLHH2TQPp',
       //  Host:'el.inspur.com'
    }

},(res) => {
    console.log(`STATUS: ${res.statusCode}`);
    res.setEncoding('utf8');

    let htmlData = '';
    res.on('data', (chunk) => {
        htmlData += chunk;
    });

    res.on('end', () => {
        //console.log(htmlData);
       let $ = cheerio.load(htmlData);
       let lesson = [];

       $('.Nsb_r_list tr').each((i, element) => {
            $element = $(element);
            if(!i) return;
           lesson.push({
               projName: $element.find('td').eq(0).attr('title'),
               lessonName: $element.find('td').eq(1).find('span').text(),
               signRange: $element.find('td').eq(2).text(),
               signTotal: $element.find('td').eq(3).text(),
               hasSign: $element.find('td').eq(4).text(),
               trainType: $element.find('td').eq(5).text(),
               endDate: $element.find('td').eq(6).text(),
           })

       });

       console.log(lesson);

    })

});
req.on('error', (e) => {
    console.log(`problem with request: ${e.message}`);
});

req.end()